package com.df.springmvc.system.auth.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.df.springmvc.common.bean.MsgBean;
import com.df.springmvc.common.util.WebUtil;
import com.df.springmvc.supper.SupperController;
import com.df.springmvc.system.auth.services.AuthServices;

@Controller
@RequestMapping("/system/auth/Auth")
/**
 * 本类仅做一些简单数据处理如:
 *格式验证
 *数据封装
 * @author David
 *
 */
public class AuthController extends SupperController{
	String page_classshifts="system/auth/" + this.getClass().getSimpleName().replace("Controller","") + "_";
	@Autowired
	AuthServices services;
	@Autowired
	MessageSource messageSource;
	
	public AuthController(){
		// TODO Auto-generated constructor stub
		//
	}
	@RequestMapping(value={"/"})
	public String excute(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			//获取角色
			addRequestAttribute("RoleList",services.getRoleDate());
			System.out.println("" + services);
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
		}finally{
		}
		return page_classshifts;
	}
	@RequestMapping(value={"/" + doAdd})
	public void doAdd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// WebUtil.json(response,new MsgBean("OK"));
		try{
			Object rs=services.add(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 获取系统列表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSystem")
	public void getSystem(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			Object o=services.getGetSystem();
			WebUtil.json(response,new MsgBean(o));
			// WebUtil.json(response,new MsgBean(gridBean));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
	/**
	 * 根据系统获取权限列表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getSystemModular")
	public void getSystemModular(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			List<Map<String,Object>> list=(List<Map<String,Object>>)services.getAuthDate(getParamMap(request,"map").get("systemCode"));
			WebUtil.json(response,new MsgBean(list));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
	/**
	 * 根据角色编号获取权限
	 * @param roleCode
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getAuthCode")
	public void getAuthCode(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			Object o=services.getAuthCode(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(o));
			// WebUtil.json(response,new MsgBean(gridBean));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
}
